import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import set from '@dfeidao/atom-web/local/set';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import render from '@dfeidao/atom-web/render/render';
// import setClass from "@dfeidao/atom-web/ui/set-node-cls";
import whoami from '../../atom/whoami';
import p004 from './p04';
export default async function a004(fd: IFeidaoAiBrowserComponent) {
	// todo
	// fire('zjc-000005', 'a001');
	// console.log("sssssssssssssssssssss");
	const res = await whoami(fd);
	const a = res.params as { productid: string, staff_no: string };
	const staff_no = a.staff_no;
	// const staff_no = 'YG000029';
	const productid = res.params.productid;
	set(fd, 'productid', productid);
	set(fd, 'staff_no', staff_no);
	const query = {
		productid,
		staff_no
	};
	/**
	 * 拿到总条数
	 */
	// const total_count = await nodejs<{ size: number }>('common/zjc-000001/s004', query);
	// console.log(total_count);
	// console.log('sizesizesize:' + size);

	const data = await nodejs<{ array1: Array<{}>, array2: Array<{}>, array3: Array<{}> }>('common/zjc-000001/s003', query);
	// console.log('datadatadata:');
	let size = 0;
	// console.log(data);
	if (data.array2.length > 0) {
		size = data.array1.length;
		render(fd, data.array1, p004, 'P004', 'inner');
	} else {
		size = data.array3.length;
		render(fd, data.array3, p004, 'P004', 'inner');
	}

	const d = fd.data.node.querySelector('[data-mess="message"]') as HTMLDivElement;
	if (size > 99) {
		d.innerText = size + "+";
		d.parentElement.setAttribute("style", "width: 20px;height: 20px;top: -10px;right: -10px;border-radius: 50%;background:rgba(238,0,0,1)");
	} else if (size === 0) {
		// d.parentElement.setAttribute("style", "width: 20px;height: 20px;top: -10px;right: -10px;border-radius: 50%;");
		d.innerText = "";
	} else {
		d.parentElement.setAttribute("style", "width: 20px;height: 20px;top: -10px;right: -10px;border-radius: 50%;background:rgba(238,0,0,1)");
		d.innerText = size + "";
	}
}
